import {
	openWin,
	ajax,
	getUserInfo
} from '@/common/common.js'
import {
	Url,
	bpmUrl
} from "@/common/config.js"
import Tips from "@/common/utils/tips.js"
const user=getUserInfo()
const method = {
	//直接归档
	GoToArchived(orUnid, user,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/archived"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.toast(res.data.msg, "none")
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}
	
			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	
	//完成会签（同意与不同意）
	GoToNextParallelUser(orUnid, user,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/goto/nextCountersignedActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.toast(res.data.msg, "none")
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}
	
			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	
	//提交下一审批用户//提交
	GoToNextSerialUser(orUnid, user,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/goto/simultaneouslyActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.toast(res.data.msg, "none")
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//提交下一审批用户
	// GoToNextSerialUser() {
	// 	let params = {
	// 		paramasMap: {
	// 			docUnid: this.orUnid
	// 		},
	// 		headersMap: {
	// 			sysid: "bpm",
	// 			syspwd: "pass",
	// 			userid: user.bpmUid
	// 		},
	// 		url: this.bpmUrl + "/rest/task/route/goto/simultaneouslyActor"
	// 	};
	// 	ajax({
	// 		url: '/bpm/post',
	// 		method: 'POST',
	// 		data: params,
	// 		success: res => {
	// 			console.log(res)
	// 			if (res.code == 0) {
	// 				if (res.data.status == 1) {
	// 					Tips.toast(res.data.msg, "none")
	// 				} else {
	// 					Tips.toast(res.data.msg, "none")
	// 				}
	// 			}

	// 		},
	// 		fail: res => {
	// 			Tips.toast('获取失败', 'none')
	// 			Tips.loaded()
	// 		}
	// 	})
	// },
	//回退任意环节
	ReturnToAnyNode(orUnid,user,remark,nextNodeId,nextUserList,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				nextNodeId: nextNodeId, //要启动的节点id
				nextUserList: nextUserList ,//要启动的用户id
				remark:remark,
				formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: this.bpmUrl + "/rest/task/route/back/anyNode"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.toast(res.data.msg, "none")
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//返回回退者
	BackToReturnUser(orUnid,user,remark,formatDate) {
		let params = {
			paramasMap: {
				docUnid:orUnid,
				remark: remark,
				// formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: this.bpmUrl + "/rest/task/route/back/rollbackActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.toast(res.data.msg, "none")
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//返回转交者
	ReturnToPrevUser(orUnid, user,remark,formatDate) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				// formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/back/deliverActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {

					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//回退上一环节
	GoToPrvNode(orUnid, user,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				formData:formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/back/prevNode"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {

					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//拒绝
	GoToFirstNode(orUnid, user,remark,formData,isBackFlag) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark:remark,
				formData:formData,
				isBackFlag:isBackFlag
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/back/firstNode"
		};
		console.log(params)
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {
						Tips.loaded()
						Tips.toast(res.data.msg, "none")
					
					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//回上一用户
	GoToPrvUser(orUnid, user,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				remark: remark,
				formData: formData
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/back/prevActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {

					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
	//转他人处理
	GoToReassignment(orUnid, user,nextUserList,remark,formData) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				nextUserList: nextUserList, //要转交的用户id多个用逗号分隔
				remark: remark,
				formData: formData

			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/task/route/goto/deliverActor"
		};
		ajax({
			url: '/bpm/post',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {

					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},

	//点击审批按钮
	GoToNextNode(parm,urltype) {
		let promise = new Promise(function (resolve,reject) {
			console.log("12")
			console.log(parm,urltype)
			let params = {
				paramasMap: parm,
				headersMap: {
					sysid: "bpm",
					syspwd: "pass",
					userid: user.bpmUid
				},
				url: bpmUrl + urltype
			};
			console.log(params.urltype)
			ajax({
				url: '/bpm/post',
				method: 'POST',
				data: params,
				success: res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data.Status == "1") {
							// Tips.loaded()
							console.log("2")
							Tips.toast(res.data.msg, "none")

						} else {
							Tips.toast(res.data.msg, "none")
						}
					}
					resolve()
				},
				fail: res => {
					Tips.toast('获取失败', 'none')
					Tips.loaded()
					reject()
				}
			})
		})
		return promise;
	},
	//点击获取可修改字段
	getchangefiled(orUnid, processid) {
		let params = {
			paramasMap: {
				docUnid: orUnid,
				processId: processid,
			},
			headersMap: {
				sysid: "bpm",
				syspwd: "pass",
				userid: user.bpmUid
			},
			url: bpmUrl + "/rest/process/node/field "
		};
		console.log(params)
		ajax({
			url: '/bpm/get',
			method: 'POST',
			data: params,
			success: res => {
				console.log(res)
				if (res.code == 0) {
					if (res.data.status == 1) {

					} else {
						Tips.toast(res.data.msg, "none")
					}
				}

			},
			fail: res => {
				Tips.toast('获取失败', 'none')
				Tips.loaded()
			}
		})
	},
}
export {
	method
}
